﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using GFE.SharePoint.Attributes;

namespace GFE.SharePoint.Lazy
{
    public static class GFEMethodInfoExtensions
    {
        public static bool HasMEFMethodAttribute<T>(this MethodInfo Method)
        {
            object[] attributes;
            attributes =
                Method.GetCustomAttributes(
                    typeof(T), false);

            return attributes.Any();
        }
        public static Dictionary<string, MethodInfo> GetMEFMethodDictionay<T>(this Type ObjectType)
        {
            var JSONMemberList = new Dictionary<string, MethodInfo>();
            foreach (var _method in ObjectType.GetMethods())
            {
                if (_method.HasMEFMethodAttribute<GFEJSONMethodAttribute>())
                    JSONMemberList.Add(_method.Name, _method);
            }
            return JSONMemberList;
        }
    }
}
